using Aliphant.Common;

using GRPCDemo.Protocol;

namespace Common.NetWork
{
    public class MessageDispatch<T> : Singleton<MessageDispatch<T>>
    {
        public void Dispatch(T sender, NetMessageRequest request)
        {
            if (request.UserConnectRequest != null) MessageDistributer<T>.Instance.RaiseEvent(sender, request.UserConnectRequest);
            if (request.EnterChatRoomRequest != null) MessageDistributer<T>.Instance.RaiseEvent(sender, request.EnterChatRoomRequest);
            if (request.ExitChatRoomRequest != null) MessageDistributer<T>.Instance.RaiseEvent(sender, request.ExitChatRoomRequest);
            if (request.SendMessageRequest != null) MessageDistributer<T>.Instance.RaiseEvent(sender, request.SendMessageRequest);
            if (request.UserLoginRequest != null) MessageDistributer<T>.Instance.RaiseEvent(sender, request.UserLoginRequest);
            if (request.UserRegistRequest != null) MessageDistributer<T>.Instance.RaiseEvent(sender, request.UserRegistRequest);
            if (request.NReadRequest != null) MessageDistributer<T>.Instance.RaiseEvent(sender, request.NReadRequest);
            if (request.LicenseRequest != null) MessageDistributer<T>.Instance.RaiseEvent(sender, request.LicenseRequest);
            if (request.UserLoginOutRequest != null) MessageDistributer<T>.Instance.RaiseEvent(sender, request.UserLoginOutRequest);
        }

        public void Dispatch(T sender, NetMessageResponse response)
        {
            if (response.UserConnectResponse != null) MessageDistributer<T>.Instance.RaiseEvent(sender, response.UserConnectResponse);
            if (response.EnterChatRoomResponse != null) MessageDistributer<T>.Instance.RaiseEvent(sender, response.EnterChatRoomResponse);
            if (response.ExitChatRoomResponse != null) MessageDistributer<T>.Instance.RaiseEvent(sender, response.ExitChatRoomResponse);
            if (response.SendMessageResponse != null) MessageDistributer<T>.Instance.RaiseEvent(sender, response.SendMessageResponse);
            if (response.UserLoginResponse != null) MessageDistributer<T>.Instance.RaiseEvent(sender, response.UserLoginResponse);
            if (response.UserRegistResponse != null) MessageDistributer<T>.Instance.RaiseEvent(sender, response.UserRegistResponse);
            if (response.NReadResponse != null) MessageDistributer<T>.Instance.RaiseEvent(sender, response.NReadResponse);
            if (response.LicenseResponse != null) MessageDistributer<T>.Instance.RaiseEvent(sender, response.LicenseResponse);
            if (response.UserLoginOutResponse != null) MessageDistributer<T>.Instance.RaiseEvent(sender, response.UserLoginOutResponse);
        }
    }
}
